package com.flybear.aqi.cmdprocess;

import com.flybear.aqi.client.ElasticSearchClient;
import com.flybear.aqi.client.EsUtil;
import com.xxl.job.core.util.JacksonUtil;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class Task implements Runnable {
    private Logger log = LoggerFactory.getLogger(getClass());
    private Map<String,String> cmddata;
    private String clientip;

    public Task(String clientip,Map<String,String> cmddata){
        this.clientip=clientip;
        this.cmddata=cmddata;
    }
    @Override
    public void run() {
        log.info("cmd process thread {} staring receive msg from {} msg is{}",Thread.currentThread().getName(),clientip,cmddata);
        String mn=cmddata.get("MN");
        ChannelService.clientipsdeviceid.putIfAbsent(mn,clientip);//TODO 变了
        //1.parse cmd ##1234QN=20160802000000001;ST=32;CN=2031;PW=123456;MN=010000A8900016F000169DC0;Flag=5;CP=&&DataTime=20160801000000;w00000-Cou=1512.0,w00000-Min=16.4,w00000-Avg=17.5,w00000-Max=20.1,w00000-Flag=N;w01001-Min=7.1,w01001-Avg=7.5,w01001-Max=7.8,w01001-Flag=N;w01018-Cou=2142.0,w01018-Min=40.1,w01018-Avg=40.1,w01018-Max=40.1,w01018-Flag=N;&&
//      String jsonstring=  JacksonUtil.writeValueAsString(cmddata);

        try {
            EsUtil.client.addEvent(cmddata,"aqi-"+DateTime.now().toString("yyyyMMdd") ,"aqi",0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
